// dateUtil.js
export function formatDate(value, format = "yyyy-MM-dd") {
	if (!value) {
		return value;
	}
	if (typeof value === "object") {
		// 使用 Intl.DateTimeFormat 进行日期格式化
		const options = {
			year: 'numeric',
			month: '2-digit',
			day: '2-digit'
		};
		return new Intl.DateTimeFormat(format || 'en-US', options).format(value);
	} else if (typeof value === "string") {
		value = new Date(Date.parse(value));
		const options = {
			year: 'numeric',
			month: '2-digit',
			day: '2-digit'
		};
		return new Intl.DateTimeFormat(format || 'en-US', options).format(value);
	} else {
		return "";
	}
}

export function formatTime(value, format) {
	const date = new Date(value);
	const year = date.getFullYear();
	const month = (date.getMonth() + 1).toString().padStart(2, '0');
	const day = date.getDate().toString().padStart(2, '0');
	const hours = date.getHours().toString().padStart(2, '0');
	const minutes = date.getMinutes().toString().padStart(2, '0');

	let formattedDate = format;
	formattedDate = formattedDate.replace('yyyy', year);
	formattedDate = formattedDate.replace('MM', month);
	formattedDate = formattedDate.replace('dd', day);
	formattedDate = formattedDate.replace('hh', hours);
	formattedDate = formattedDate.replace('mm', minutes);
	return formattedDate;
}